package com.app.aipass.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.aipass.R;
import com.app.aipass.entity.ExchangeHomeEntity;
import com.app.aipass.utils.GlideUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: woking
 * @date: 2021/6/23
 * @description：
 */
public class ExchangeHomeAdapter extends BaseAdapter {
    private List<ExchangeHomeEntity.Coin> mDatas = new ArrayList<>();
    private Context mContext = null;

    public ExchangeHomeAdapter(Context context, List<ExchangeHomeEntity.Coin> datas) {
        mDatas = datas;
        mContext = context;
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh;
        if (view == null) {
            vh = new ViewHolder();
            view = LayoutInflater.from(mContext).inflate(R.layout.item_exchangehome_list, null);
            vh.ad_img = (ImageView) view.findViewById(R.id.ad_img);
            vh.tv_name = (TextView) view.findViewById(R.id.tv_name);
            vh.tv_yue = (TextView) view.findViewById(R.id.tv_yue);
            view.setTag(vh);
        } else {
            vh = (ViewHolder) view.getTag();
        }
        if(mDatas != null && i < mDatas.size())
        {
//        vh.id.setText(mDatas.get(i).id);
            vh.tv_name.setText(mDatas.get(i).coin_name);
//        vh.tv_yue.setText(mDatas.get(i).phone);
            GlideUtils.getInstances().loadRoundCornerImg(mContext,vh.ad_img,10,mDatas.get(i).image);
        }
        return view;
    }

    public final class ViewHolder {
        public ImageView ad_img;
        public TextView tv_name;
        public TextView tv_yue;
    }
}